
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.templates.commands.CommandBase;
import edu.wpi.first.wpilibj.templates.commands.LowerBridge;
import edu.wpi.first.wpilibj.templates.commands.RaiseBridgeArm;

/**
 * This class is the glue that binds the controls on the physical operator
 * interface to the commands and command groups that allow control of the robot.
 */
public class OI {
    //// CREATING BUTTONS
    // One type of button is a joystick button which is any button on a joystick.
    // You create one by telling it which joystick it's on and which button
    // number it is.
    // Joystick stick = new Joystick(port);
    // Button button = new JoystickButton(stick, buttonNumber);
    
    // Another type of button you can create is a DigitalIOButton, which is
    // a button or switch hooked up to the cypress module. These are useful if
    // you want to build a customized operator interface.
    // Button button = new DigitalIOButton(1);
    
    // There are a few additional built in buttons you can use. Additionally,
    // by subclassing Button you can create custom triggers and bind those to
    // commands the same as any other Button.
    
    //// TRIGGERING COMMANDS WITH BUTTONS
    // Once you have a button, it's trivial to bind it to a button in one of
    // three ways:
    
    // Start the command when the button is pressed and let it run the command
    // until it is finished as determined by it's isFinished method.
    // button.whenPressed(new ExampleCommand());
    
    // Run the command while the button is being held down and interrupt it once
    // the button is released.
    // button.whileHeld(new ExampleCommand());
    
    // Start the command when the button is released  and let it run the command
    // until it is finished as determined by it's isFinished method.
    // button.whenReleased(new ExampleCommand());
    
    private static OI instance = null;
    
    public static final int LEFT_JOYSTICK_PORT = 1;
    public static final int RIGHT_JOYSTICK_PORT = 2;
    public static final int THIRD_JOYSTICK_PORT = 3;
    
    Joystick leftJoystick = new Joystick(LEFT_JOYSTICK_PORT);
    Joystick rightJoystick = new Joystick(RIGHT_JOYSTICK_PORT);
    Joystick thirdJoystick = new Joystick(THIRD_JOYSTICK_PORT);
    
    public Button
            leftJs_button1 = new JoystickButton(leftJoystick, 1),
            leftJs_button2 = new JoystickButton(leftJoystick, 2),
            leftJs_button3 = new JoystickButton(leftJoystick, 3),
            leftJs_button4 = new JoystickButton(leftJoystick, 4),
            leftJs_button5 = new JoystickButton(leftJoystick, 5),
            leftJs_button6 = new JoystickButton(leftJoystick, 6),
            leftJs_button7 = new JoystickButton(leftJoystick, 7),
            leftJs_button8 = new JoystickButton(leftJoystick, 8),
            leftJs_button9 = new JoystickButton(leftJoystick, 9),
            leftJs_button10 = new JoystickButton(leftJoystick, 10),
            leftJs_button11 = new JoystickButton(leftJoystick, 11);
    
    public Button
            rightJs_button1 = new JoystickButton(rightJoystick, 1),
            rightJs_button2 = new JoystickButton(rightJoystick, 2),
            rightJs_button3 = new JoystickButton(rightJoystick, 3),
            rightJs_button4 = new JoystickButton(rightJoystick, 4),
            rightJs_button5 = new JoystickButton(rightJoystick, 5),
            rightJs_button6 = new JoystickButton(rightJoystick, 6),
            rightJs_button7 = new JoystickButton(rightJoystick, 7),
            rightJs_button8 = new JoystickButton(rightJoystick, 8),
            rightJs_button9 = new JoystickButton(rightJoystick, 9),
            rightJs_button10 = new JoystickButton(rightJoystick, 10),
            rightJs_button11 = new JoystickButton(rightJoystick, 11);
    
    public Button
            thirdJs_button1 = new JoystickButton(thirdJoystick, 1),
            thirdJs_button2 = new JoystickButton(thirdJoystick, 2),
            thirdJs_button3 = new JoystickButton(thirdJoystick, 3),
            thirdJs_button4 = new JoystickButton(thirdJoystick, 4),
            thirdJs_button5 = new JoystickButton(thirdJoystick, 5),
            thirdJs_button6 = new JoystickButton(thirdJoystick, 6),
            thirdJs_button7 = new JoystickButton(thirdJoystick, 7),
            thirdJs_button8 = new JoystickButton(thirdJoystick, 8),
            thirdJs_button9 = new JoystickButton(thirdJoystick, 9),
            thirdJs_button10 = new JoystickButton(thirdJoystick, 10),
            thirdJs_button11 = new JoystickButton(thirdJoystick, 11);
            
    public OI() {
        //Bind commands to buttons
        
        thirdJs_button2.whileHeld(new LowerBridge());
        thirdJs_button3.whileHeld(new RaiseBridgeArm());
        //CommandBase.chassis.straight();
    }
    
    public static OI getInstance() {
        if(instance == null) {
            instance = new OI();
        }
        return instance;
    }
    
    public Joystick getLeftJoystick() {
        return leftJoystick;
    }
    
    public Joystick getRightJoystick() {
        return rightJoystick;
    }
    
    public Joystick getThirdJoystick() {
        return thirdJoystick;
    }
}

